home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
gdb
/
gdb_18s.zoo
/
stack.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-25
|
17KB
|
621 lines
/* Print and select stack frames for GDB, the GNU debugger.
Copyright (C) 1986, 1987 Free Software Foundation, Inc.
GDB is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. No author or distributor accepts responsibility to anyone
for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing.
Refer to the GDB General Public License for full details.
Everyone is granted permission to copy, modify and redistribute GDB,
but only under the conditions described in the GDB General Public
License. A copy of this license is supposed to have been given to you
along with GDB so you can know your rights and responsibilities. It
should be in a file named COPYING. Among other things, the copyright
notice and this notice must be preserved on all copies.
In other words, go ahead and share GDB, but don't try to stop
anyone else from sharing it farther. Help stamp out software hoarding!
*/
#include <stdio.h>
#include "defs.h"
#include "param.h"
#include "symtab.h"
#include "frame.h"
/* Thie "selected" stack frame is used by default for local and arg access.
May be zero, for no selected frame. */
FRAME selected_frame;
/* Level of the selected frame:
0 for innermost, 1 for its caller, ...
or -1 for frame specified by address with no defined level. */
int selected_frame_level;
/* Nonzero means print the full filename and linenumber
when a frame is printed, and do so in a format programs can parse. */
int frame_file_full_name = 0;
static void select_calling_frame ();
void print_frame_info ();
/* Print a stack frame briefly. FRAME should be the frame address
and LEVEL should be its level in the stack (or -1 for level not defined).
This prints the level, the function executing, the arguments,
and the file name and line number.
If the pc is not at the beginning of the source line,
the actual pc is printed at the beginning.
If SOURCE is 1, print the source line as well.
If SOURCE is -1, print ONLY the source line. */
static void
print_stack_frame (frame, level, source)
FRAME frame;
int level;
int source;
{
struct frame_info fi;
fi = get_frame_info (frame);
print_frame_info (&fi, level, source, 1);
}
void
print_frame_info (fi, level, source, args)
struct frame_info *fi;
register int level;
int source;
int args;
{
register FRAME frame = fi->frame;
struct symtab_and_line sal;
struct symbol *func;
register char *funname = 0;
int numargs;
sal = find_pc_line (fi->pc, fi->next_frame);
func = get_frame_function (frame);
if (func)
funname = SYMBOL_NAME (func);
else
{
register int misc_index = find_pc_misc_function (fi->pc);
if (misc_index >= 0)
funname = misc_function_vector[misc_index].name;
}
if (source >= 0 || !sal.symtab)
{
/* This avoids a bug in cc on the sun. */
struct frame_info tem;
tem = *fi;
if (level >= 0)
printf_filtered ("#%-2d ", level);
if (fi->pc != sal.pc || !sal.symtab)
printf_filtered ("0x%x in ", fi->pc);
printf_filtered ("%s (", funname ? funname : "??");
if (args)
{
FRAME_NUM_ARGS (numargs, tem);
print_frame_args (func, FRAME_ARGS_ADDRESS (tem), numargs, stdout);
}
printf_filtered (")");
if (sal.symtab)
printf_filtered (" (%s line %d)", sal.symtab->filename, sal.line);
printf_filtered ("\n");
}
if (source != 0 && sal.symtab)
{
int done = 0;
int mid_statement = source < 0 && fi->pc != sal.pc;
if (frame_file_full_name)
done = identify_source_line (sal.symtab, sal.line, mid_statement);
if (!done)
{
if (mid_statement)
printf_filtered ("0x%x\t", fi->pc);
print_source_lines (sal.symtab, sal.line, sal.line + 1);
}
current_source_line = max (sal.line - 5, 1);
}
if (source != 0)
set_default_breakpoint (1, fi->pc, sal.symtab, sal.line);
fflush (stdout);
}
/* Call here to print info on selected frame, after a trap. */
void
print_sel_frame (just_source)
int just_source;
{
print_stack_frame (selected_frame, -1, just_source ? -1 : 1);
}
/* Print info on the selected frame, including level number
but not source. */
print_selected_frame ()
{
print_stack_frame (selected_frame, selected_frame_level, 0);
}
/* Print verbosely the selected frame or the frame at address ADDR.
This means absolutely all information in the frame is printed. */
static void
frame_info (addr_exp)
char *addr_exp;
{
FRAME frame = addr_exp ? parse_and_eval_address (addr_exp) : selected_frame;
struct frame_info fi;
struct frame_saved_regs fsr;
struct symtab_and_line sal;
struct symbol *func;
FRAME calling_frame;
int i, count;
char *funname = 0;
int numargs;
fi = get_frame_info (frame);
get_frame_saved_regs (&fi, &fsr);
sal = find_pc_line (fi.pc, fi.next_frame);
func = get_frame_function (frame);
if (func)
funname = SYMBOL_NAME (func);
else
{
register int misc_index = find_pc_misc_function (fi.pc);
if (misc_index >= 0)
funname = misc_function_vector[misc_index].name;
}
calling_frame = get_prev_frame (frame);
if (!addr_exp && selected_frame_level >= 0)
printf_filtered ("Stack level %d, frame at 0x%x:\n pc = 0x%x",
selected_frame_level, frame, fi.pc);
else
printf_filtered ("Stack frame at 0x%x:\n pc = 0x%x",
frame, fi.pc);
if (funname)
printf_filtered (" in %s", funname);
if (sal.symtab)
printf_filtered (" (%s line %d)", sal.symtab->filename, sal.line);
printf_filtered ("; saved pc 0x%x\n", FRAME_SAVED_PC (frame));
if (calling_frame)
printf_filtered (" called by frame at 0x%x", calling_frame);
if (fi.next_frame && calling_frame)
printf_filtered (",");
if (fi.next_frame)
printf_filtered (" caller of frame at 0x%x", fi.next_frame);
if (fi.next_frame || calling_frame)
printf_filtered ("\n");
printf_filtered (" Arglist at 0x%x,", FRAME_ARGS_ADDRESS (fi));
FRAME_NUM_ARGS (i, fi);
if (i < 0)
printf_filtered (" args: ");
else if (i == 0)
printf_filtered (" no args.");
else if (i == 1)
printf_filtered (" 1 arg: ");
else
printf_filtered (" %d args: ", i);
FRAME_NUM_ARGS (numargs, fi);
print_frame_args (func, FRAME_ARGS_ADDRESS (fi), numargs, stdout);
printf_filtered ("\n");
count = 0;
for (i = 0; i < NUM_REGS; i++)
if (fsr.regs[i])
{
if (count % 4 != 0)
printf_filtered (", ");
else
{
if (count == 0)
printf_filtered (" Saved registers:");
printf_filtered ("\n ");
}
printf_filtered ("%s at 0x%x", reg_names[i], fsr.regs[i]);
count++;
}
if (count)
printf_filtered ("\n");
}
/* Print briefly all stack frames or just the innermost COUNT frames. */
static void
backtrace_command (count_exp)
char *count_exp;
{
struct frame_info fi;
register int count;
register FRAME frame;
register int i;
if (count_exp)
count = parse_and_eval_address (count_exp);
else
count = -1;
for (i = 0, frame = get_current_frame (), fi = get_frame_info (frame);
frame && count--;
i++, fi = get_prev_frame_info (fi.frame), frame = fi.frame)
{
QUIT;
print_frame_info (&fi, i, 0, 1);
}
}
/* Print the local variables of a block B active in FRAME. */
static void
print_block_frame_locals (b, frame, stream)
struct block *b;
register FRAME frame;
register FILE *stream;
{
int nsyms;
register int i;
register struct symbol *sym;
nsyms = BLOCK_NSYMS (b);
for (i = 0; i < nsyms; i++)
{
sym = BLOCK_SYM (b, i);
if (SYMBOL_CLASS (sym) == LOC_LOCAL
|| SYMBOL_CLASS (sym) == LOC_REGISTER
|| SYMBOL_CLASS (sym) == LOC_STATIC)
{
fprintf_filtered (stream, "%s = ", SYMBOL_NAME (sym));
print_variable_value (sym, frame, stream);
fprintf_filtered (stream, "\n");
fflush (stream);
}
}
}
/* Print on STREAM all the local variables in frame FRAME,
including all the blocks active in that frame
at its current pc.
Returns 1 if the job was done,
or 0 if nothing was printed because we have no info
on the function running in FRAME. */
static i